@extends('layouts.app')

@section('content')
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><i class="fa fa-fw fa-cog"></i>单位管理</li>
                <li>行业字段设置</li>
            </ul>
        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <a href="{{url('admin/units/add_field',$id)}}" class="easyui-linkbutton" iconCls="icon-add">添加</a>
                &nbsp;&nbsp;<a href="{{url('admin/units/type')}}" class="easyui-linkbutton" iconCls="icon-undo">返回上级</a>
                <div class="form-all">
                    <table class="table table-form table-striped table-bordered table-condensed">
                        <thead>
                        <tr>
                            <th width="80">序号</th>
                            <th>字段内容</th>
                            <th>字段名</th>
                            <th>排序</th>
                            <th>修改时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($res as $key=>$re)
                            <tr>
                                <td>{{ $key+1 }}</td>
                                <td>{{ $re->field_content }}</td>
                                <td>{{ $re->field_name }}</td>
                                <td class="sort"><span class="old" style="cursor: pointer">{{ $re->paixu }}</span><input type="text" class="new" name="paixu" value="{{ $re->paixu }}" id="{{ $re->id }}" style="display: none"></td>
                                <td>{{ $re->updated_at }}</td>
                                <td>
                                    @if($re->is_show==1)<span style="color:#4cae4c">显示</span>
                                    @elseif($re->is_show==2)<span style="color:#f0ad4e">隐藏</span>
                                    @endif
                                </td>
                                <td>
                                    <a href="{{url('admin/units/edit_field',$re->id)}}" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
                                    <a href="{{url('admin/units/del_field',$re->id)}}" class="easyui-linkbutton del" iconCls="icon-cancel" plain="true">删除</a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <span>共{{$count}}条数据</span>
                <ul class="pagination pull-right">
                    {{ $res->render() }}
                </ul>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        function check() {
            $('#search_form').submit();
        }

        $('.del').click(function(){
            var i=window.confirm("确认删除该数据？");
            if(i==0){
                return false;
            }
        });
        $(document).on("dblclick",'.sort', function(){
            $(this).children().eq(0).attr('style','display:none');
            $(this).children().eq(1).attr('style','width:40px;display:block;');
            $(this).children().eq(1).focus();
        });
        $(document).on("blur",'.new', function(){
            var url = "{{url('admin/units/save_field_sort')}}";
            var id = $(this).attr('id');
            var paixu = $(this).val();
            $(this).prev().attr('style','cursor:pointer');

            $(this).attr('style','width:40px;display:none');
            var tt = $(this);
            if(paixu){
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: {'id':id,'paixu': paixu,'_token':'{{csrf_token()}}'},
                    success: function(data){
                        if(data.code == 403){
                            alert(data.msg);
                        }else{
                            tt.prev().text(paixu);
                        }
                    }
                });
            }
        });
    </script>
@stop

